package com.qqt.csr.order.controller;

import com.qqt.csr.common.interceptor.auth.Authorize;
import com.qqt.csr.common.vo.resp.ObjectResponse;
import com.qqt.csr.order.service.OrderDynamicService;
import com.qqt.csr.order.vo.req.CommentWorkOrderReqVO;
import com.qqt.csr.order.vo.req.ReplyWorkOrderReqVO;
import com.qqt.csr.order.vo.resp.OrderDynamicRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: yang hao
 * @Date: 2024/12/18 14:19
 * @Description: 工单动态
 **/
@Authorize
@RestController
@RequestMapping("order/dynamic")
@Tag(name = "工单动态", description = "工单动态")
public class OrderDynamicController {

    @Autowired
    private OrderDynamicService orderDynamicService;

    @PostMapping("/remove/{id}")
    @Operation(summary = "删除动态")
    public ObjectResponse<Boolean> remove(@PathVariable("id") @NotNull(message = "动态id不能为空") Long id) {
        boolean result = orderDynamicService.deleteById(id);
        return ObjectResponse.success(result);
    }

    @PostMapping("/comment")
    @Operation(summary = "评论工单")
    public ObjectResponse<Boolean> comments(@RequestBody @Validated CommentWorkOrderReqVO reqVO) {
        boolean result = orderDynamicService.comments(reqVO.getOrderId(), reqVO.getContent());
        return ObjectResponse.result(result);
    }

    @PostMapping("/reply")
    @Operation(summary = "回复工单")
    public ObjectResponse<Boolean> reply(@RequestBody @Validated ReplyWorkOrderReqVO reqVO) {
        boolean result = orderDynamicService.commentsReply(reqVO.getDynamicId(), reqVO.getContent());
        return ObjectResponse.result(result);
    }

    @GetMapping("/list/{id}")
    @Operation(summary = "查询工单动态")
    public ObjectResponse<List<OrderDynamicRespVO>> list(@PathVariable("id") Long orderId) {
        List<OrderDynamicRespVO> list = orderDynamicService.list(orderId);
        return ObjectResponse.success(list);
    }

}
